Record, Save, and Play Moves on a Poppy Creature

This notebook is still work in progress! Feedbacks are welcomed!

In this tutorial we will show how to:

  • record moves by direct demonstration on a Poppy Creature
  • save them to the disk - and re-load them
  • play, and re-play the best moves

To follow this notebook, you should already have installed everything needed to control a Poppy Creature. The examples below used a Poppy Ergo but then can be easily transposed to a Poppy Humanoid or to any other creatures.

Connect to your Poppy Creature

First, connect to your Poppy Creature and put it in its "base" position so you can easily record motions.

Here we use a Poppy Ergo but you can replace it by a Poppy Humanoid.


In [1]:
from poppy.creatures import PoppyErgo

poppy = PoppyErgo()

In [2]:
for m in poppy.motors:
    m.compliant = False
    m.goal_position = 0.0

Import the Move, Recorder and Player


In [3]:
# Import everything you need for recording, playing, saving, and loading Moves

# Move: object used to represent a movement
# MoveRecorder: object used to record a Move
# MovePlayer: object used to play (and re-play) a Move

from pypot.primitive.move import Move, MoveRecorder, MovePlayer

Create a Recorder for the robot Poppy


In [4]:
record_frequency = 50.0 # This means that a new position will be recorded 50 times per second.
recorded_motors = [poppy.m4, poppy.m5, poppy.m6] # We will record the position of the 3 last motors of the Ergo

# You can also use alias for the recorded_motors
# e.g. recorder = MoveRecorder(poppy, record_frequency, poppy.tip)
# or even to record all motors position
# recorder = MoveRecorder(poppy, record_frequency, poppy.motors)

recorder = MoveRecorder(poppy, record_frequency, recorded_motors)

Start the recording

First, turn the recorded motors compliant, so you can freely move them:


In [5]:
for m in recorded_motors:
    m.compliant = True

Starts the recording when you are ready!


In [6]:
recorder.start()

Stop the recording

Stop it when you are done demonstrating the movement.


In [7]:
recorder.stop()

Turn back off the compliance.


In [8]:
for m in recorded_motors:
    m.compliant = False

Get the recorder Move and store it on the disk

Save the recorded move on the text file named 'mymove.json'.


In [9]:
recorded_move = recorder.move

with open('mymove.json', 'w') as f:
    recorded_move.save(f)

Load a saved Move

Re-load it from the file jsut as an example purpose.


In [11]:
with open('mymove.json') as f:
    loaded_move = Move.load(f)

Create a Move Player and Play Back a Recorded Move

First, create the object used to re-play a recorded Move.


In [12]:
player = MovePlayer(poppy, loaded_move)

You can start the play back whenever you want:


In [13]:
player.start()

You can play your move as many times as you want. Note, that we use the wait_to_stop method to wait for the first play abck to end before running it again.


In [15]:
for _ in range(3):
    player.start()
    player.wait_to_stop()